// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   OptionAction.java

package com.boci.clientapp.trading.action;

import com.boci.clientapp.main.*;
import com.boci.clientapp.trading.OptReviewScrPanel;
import com.boci.clientapp.trading.OptionScrPanel;
import com.boci.clientapp.trading.handler.BalanceSummaryHandler;
import com.boci.clientapp.trading.handler.OptionHandler;
import com.boci.common.action.AbstractAction;
import com.boci.common.constant.RequestTypeConst;
import com.boci.common.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.logging.Logger;

public class OptionAction extends AbstractAction
{

    public OptionAction()
    {
    }

    private void addExtraValues(HashMap pInpMap, String pActionType, boolean pHKMktFlag, String pOrderType)
    {
        if(!pHKMktFlag && pOrderType != null && pOrderType.equals("MKT"))
            pInpMap.put("testValue", "GetQuote");
        else
            pInpMap.put("testValue", "ReviewBeforeSending");
        pInpMap.put("testValue1", "yyy");
        pInpMap.put("select2", appServ.getAccountNo());
        if(pActionType.equals("BUY"))
            pInpMap.put("radiobutton", "BUY");
        else
        if(pActionType.equals("SELL"))
            pInpMap.put("radiobutton", "SELL");
    }

    public void doProcess(HashMap pInpMap, String pActionType)
    {
    	try{
	        String strModName;
	        String strReviewScrName;
	        OptionScrPanel optPanel;
	        OptReviewScrPanel reviewPanel;
	        strModName = "TRADING_MODULE";
	        String strOptScrName = "OPTION_SCREEN";
	        strReviewScrName = "REVIEW_OPTION_SCREEN";
	        optPanel = (OptionScrPanel)appServ.getMainPanel().getPanel(strModName, strOptScrName);
	        reviewPanel = (OptReviewScrPanel)appServ.getMainPanel().getPanel(strModName, strReviewScrName);
	        appServ.setBusy(true);
	        if(pActionType.equals("BUY") || pActionType.equals("SELL"))
	        {
	            reviewPanel.resetDuplicateFlag();
	            String orderType = (String)pInpMap.get("ordtype");
	            addExtraValues(pInpMap, pActionType, optPanel.getHKOptFlag(), orderType);
	            if(optPanel.getHKOptFlag())
	            {
	                String strReqType = RequestTypeConst.BOCI_HK_OPTION_REVW_URL;
	                OptionHandler optionHandler = new OptionHandler(strReqType);
	                reviewPanel.refresh(optionHandler.reviewHKOption(pInpMap));
	            } else
	            {
	                String strReqType = RequestTypeConst.BOCI_US_OPTION_REVW_URL;
	                OptionHandler optionHandler = new OptionHandler(strReqType);
	                reviewPanel.refresh(optionHandler.reviewUSOption(pInpMap));
	            }
	            appServ.getMainPanel().showScreen(strModName, strReviewScrName);
	        } else
	        if(pActionType.equals("CLEAR"))
	            optPanel.clearText();
	        else
	        if(pActionType.equals("HK_OPTION"))
	            optPanel.chgOption(pActionType);
	        else
	        if(pActionType.equals("US_OPTION"))
	            optPanel.chgOption(pActionType);
	        else
	        if(pActionType.equals("SHOW BALANCE"))
	        {
	            HashMap map = new HashMap();
	            map.put("selectAcct", appServ.getAccountNo());
	            String strReqType = RequestTypeConst.BOCI_BALANCE_SIMPLE_URL;
	            BalanceSummaryHandler handler = new BalanceSummaryHandler(strReqType);
	            appServ.showBalanceDialog(handler.getBalanceSummary(map));
	        } else
	        if(pActionType.equals("GETQUOTE"))
	        {
	            String strUnderlyingCode = optPanel.getUnderlyingCodeSymbol();
	            if(strUnderlyingCode == null || strUnderlyingCode.trim().equals(""))
	            {
	                ArrayList msgList = new ArrayList();
	                msgList.add("TRADING.NO_UNDERLYING_CODE");
	                appServ.showWarningDialog(null, msgList);
	            } else
	            if(optPanel.getHKOptFlag())
	                appServ.showGetQuoteInfo("HK_MARKET", strUnderlyingCode);
	            else
	                appServ.showGetQuoteInfo("US_MARKET", strUnderlyingCode);
	        }
    	}        
    	catch(AppException appEx)
        {
            logger.info(StringUtil.formatException(appEx));
            String strError = appEx.getMessage();
            if(appEx.getErrorCode().equals("STR_US_TRADE_ORDER_LIMIT"))
                strError = strError.replaceAll("%SIZE%", ClientAppLoader.getAppConfigurator().getAppConfig("US_ORDER_SIZE"));
            appServ.showErrorDialog(null, strError);
        }
        catch(Exception sysEx)
        {
            logger.severe(StringUtil.formatException(sysEx));
            appServ.showSysErrDialog();
        }
        finally
        {
            appServ.setBusy(false);
        }
        return;
    }
}
